package com.jsz.peini.server.thread;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.jsz.peini.common.util.SpringContextUtil;
import com.jsz.peini.mapper.app.SysConfigMapper;
import com.jsz.peini.mapper.user.UserInfoMapper;

/**
 * 乐泰活动异步线程
 * @author Han Guohong
 *
 */
public class ActivityLetaiThread extends Thread{
	
	private static Logger logger = LoggerFactory.getLogger(ActivityLetaiThread.class);
	
	public void init(){
		this.start();
	}
	
	@Override
	public void run() {
		super.run();
		
		SysConfigMapper sysConfigMapper = (SysConfigMapper)SpringContextUtil.getBean(SysConfigMapper.class);
		UserInfoMapper userInfoMapper = (UserInfoMapper)SpringContextUtil.getBean(UserInfoMapper.class);
		
		while(true)
		{
			try {
				/*List<byte[]> list = RedisUtil.brpop(RedisConstants.ACTIVITY_LETAI.getBytes());
				
				if(list.size() > 0){
					ActivityUser acUser = (ActivityUser)SerializeUtil.unserialize(list.get(1));
					
					List<Integer> ids = new ArrayList<Integer>();
					ids.add(4);
					ids.add(5);
					ids.add(6);
					ids.add(7);
					SysConfigExample configExample = new SysConfigExample();
					configExample.createCriteria().andIdIn(ids);
					List<SysConfig> confList = sysConfigMapper.selectByExampleWithBLOBs(configExample);
					
					String userId = acUser.getUserId();
					UserInfo userInfo = userInfoMapper.selectByPrimaryKey(userId);
					
					if(userInfo != null){
						HashMap<String,String> paramMap = new HashMap<String,String>();
						if(StringUtils.isNotBlank(userInfo.getImageHead())){
							if(userInfo.getImageHead().startsWith("http")){
								paramMap.put("img", userInfo.getImageHead());
							}else{
								paramMap.put("img", "http://okxm4c2gg.bkt.clouddn.com/"+userInfo.getImageHead());
							}
						}else{
							paramMap.put("img", "");
						}
						paramMap.put("name", userInfo.getNickname());
						
						String tel = userInfo.getUserPhone();
						String phone = tel.substring(0, 3);
						phone += "****";
						phone += tel.substring(7, tel.length());
						paramMap.put("number", phone);
						
						for (SysConfig sysConfig : confList) {
							if(acUser.getAcId().equals(sysConfig.getConval())){
								switch (sysConfig.getId()) {
								case 4:
									paramMap.put("page", "aining");
									break;
								case 5:
									paramMap.put("page", "yanghui");
									break;
								case 6:
									paramMap.put("page", "wangyang");
									break;
								case 7:
									paramMap.put("page", "weidan");
									break;
								default:
									break;
								}
							}
						}
					}
				}*/
				
				Thread.sleep(1);
			} catch (Exception e1) {
				e1.printStackTrace();
				logger.info("fail", e1);
			}
		}
		
	}
	
}